home *** CD-ROM | disk | FTP | other *** search
- // PXEWIN - (C) Copyright 1992 by Beam Engineering, INC.
-
- // PXFIELD.CPP //
-
- // Contents ----------------------------------------------------------------
- //
- // This module contains all members to access field related classes.
- //
- // End ---------------------------------------------------------------------
-
- // External Reference Name for this Header ---------------------------------
-
- #ifndef PXFIELD_CPP
- #define PXFIELD_CPP
-
- // End ---------------------------------------------------------------------
-
- // Interface Dependencies --------------------------------------------------
-
- #ifndef PXFIELD_HPP
- #include "pxfield.hpp"
- #endif // PXFIELD_HPP //
-
- // End ---------------------------------------------------------------------
-
- // member build of PXFieldTypeBase //
-
- PTStreamable PXFieldTypeBase::build()
- {
- return new PXFieldTypeBase(streamableInit);
- }
-
- TStreamableClass RegPXFieldTypeBase("PXFieldTypeBase",PXFieldTypeBase::build,
- __DELTA(PXFieldTypeBase));
-
- // Description -------------------------------------------------------------
- //
- // When the streamable constructor is called, TStreamable dispatches
- // the build member to construct the object. To do this, it must
- // know where to find this member functions for the specific class.
- // This is the reason for the stream registration.
- //
- // End ---------------------------------------------------------------------
-
- // member read of PXFieldTypeBase //
-
- inline Pvoid PXFieldTypeBase::read(Ripstream)
- {
- return this;
- }
-
- // Description -------------------------------------------------------------
- //
- // Nothing taken from the stream.
- //
- // End ---------------------------------------------------------------------
-
- // member write of PXFieldTypeBase //
-
- inline void PXFieldTypeBase::write(Ropstream)
- {
-
- }
-
- // Description -------------------------------------------------------------
- //
- // Nothing put on the stream.
- //
- // End ---------------------------------------------------------------------
-
- // constructor PXFieldTypeChar //
-
- inline PXFieldTypeChar::PXFieldTypeChar(PPXField my_field,int sz):
- PXFieldTypeBase(my_field)
- {
- size = sz + 1;
- char_size = sz;
-
- // Create buffer space
-
- data = new char[size];
-
- char_dat = data; /* No conversion necessary
- for this type */
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Initializes a field of type char.
- //
- // Parameters
- //
- // my_field. Points to the field base object.
- //
- // sz. Size of the field in bytes.
- //
- // Description
- //
- // Set size of character data to size and char_size. Create a buffer
- // of size characters and set the char_dat pointer to this pointer.
- // Since there is no conversion necessary, the char_dat pointer is the
- // same as the data pointer.
- //
- // End ---------------------------------------------------------------------
-
- // destructor PXFieldTypeChar //
-
- inline PXFieldTypeChar::~PXFieldTypeChar(void)
- {
- delete data;
- data = NULL;
- }
-
- // Summary -----------------------------------------------------------------
- //
- // delete data buffer.
- //
- // End ---------------------------------------------------------------------
-
- // member build of PXFieldTypeChar //
-
- PTStreamable PXFieldTypeChar::build()
- {
- return new PXFieldTypeChar(streamableInit);
- }
-
- TStreamableClass RegPXFieldTypeChar("PXFieldTypeChar",PXFieldTypeChar::build,
- __DELTA(PXFieldTypeChar));
-
- // Description -------------------------------------------------------------
- //
- // When the streamable constructor is called, TStreamable dispatches
- // the build member to construct the object. To do this, it must
- // know where to find this member functions for the specific class.
- // This is the reason for the stream registration.
- //
- // End ---------------------------------------------------------------------
-
- // member read of PXFieldTypeChar //
-
- inline Pvoid PXFieldTypeChar::read(Ripstream)
- {
- return this;
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Nothing taken from the stream.
- //
- // End ---------------------------------------------------------------------
-
- // member write of PXFieldTypeChar //
-
- inline void PXFieldTypeChar::write(Ropstream)
- {
-
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Nothing put on the stream.
- //
- // End ---------------------------------------------------------------------
-
- // member Get of PXFieldTypeChar //
-
- inline int PXFieldTypeChar::Get(void)
- {
- if((EngDataPtr->Errors.pxerr = PXGetAlpha(*recHandle,fld,size,
- data)) != PXSUCCESS)
- PXError(ENG_ERROR);
- return EngDataPtr->Errors.pxerr;
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Get the character data from the record buffer.
- //
- // Return Value
- //
- // pxerr. Return PDOX error code.
- //
- // End ---------------------------------------------------------------------
-
- // member Put of PXFieldTypeChar //
-
- inline int PXFieldTypeChar::Put(void)
- {
- if((EngDataPtr->Errors.pxerr = PXPutAlpha(*recHandle,fld,data))
- != PXSUCCESS)
- PXError(ENG_ERROR);
- return EngDataPtr->Errors.pxerr;
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Put the character data into the record transfer buffer.
- //
- // Return Value
- //
- // pxerr. Returns PDOX error status.
- //
- // End ---------------------------------------------------------------------
-
- // constructor PXFieldTypeDouble //
-
- inline PXFieldTypeDouble::PXFieldTypeDouble(PPXField my_field):
- PXFieldTypeBase(my_field)
- {
- char_size = DOUBLE_SIZE;
-
- // Create buffer space
-
- data = new double;
- char_dat = new char[char_size + 1];
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Initialize double type fields.
- //
- // Parameters
- //
- // my_field. Pass the field object to copy the handles.
- //
- // Functional Description
- //
- // Set char_size to DOUBLE_SIZE for holding the text results of the
- // double value. Create the buffer space for the double number and
- // the character version of the number.
- //
- // End ---------------------------------------------------------------------
-
- // destructor PXFieldTypeDouble //
-
- inline PXFieldTypeDouble::~PXFieldTypeDouble(void)
- {
- delete data;
- data = NULL;
- delete char_dat;
- char_dat = NULL;
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Delete the data and character buffers.
- //
- // End ---------------------------------------------------------------------
-
- // member build of PXFieldTypeDouble //
-
- PTStreamable PXFieldTypeDouble::build()
- {
- return new PXFieldTypeDouble(streamableInit);
- }
-
- TStreamableClass RegPXFieldTypeDouble("PXFieldTypeDouble",PXFieldTypeDouble::build,
- __DELTA(PXFieldTypeDouble));
-
- // Description -------------------------------------------------------------
- //
- // When the streamable constructor is called, TStreamable dispatches
- // the build member to construct the object. To do this, it must
- // know where to find this member functions for the specific class.
- // This is the reason for the stream registration.
- //
- // End ---------------------------------------------------------------------
-
- // member read of PXFieldTypeDouble //
-
- inline Pvoid PXFieldTypeDouble::read(Ripstream)
- {
- return this;
- }
-
- // member write of PXFieldTypeDouble //
-
- inline void PXFieldTypeDouble::write(Ropstream)
- {
-
- }
-
- // member Get of PXFieldTypeDouble //
-
- inline int PXFieldTypeDouble::Get(void)
- {
- if((EngDataPtr->Errors.pxerr = PXGetDoub(*recHandle,fld,data))
- != PXSUCCESS)
- PXError(ENG_ERROR);
- sprintf(char_dat,"%g",*data);
- return EngDataPtr->Errors.pxerr;
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Get the double data and convert it to character data.
- //
- // Return Value
- //
- // pxerr. Return PDOX error code.
- //
- // End ---------------------------------------------------------------------
-
- // member Put of PXFieldTypeDouble //
-
- inline int PXFieldTypeDouble::Put(void)
- {
- if((EngDataPtr->Errors.pxerr = PXPutDoub(*recHandle,fld,*data))
- != PXSUCCESS)
- PXError(ENG_ERROR);
- return EngDataPtr->Errors.pxerr;
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Put the data from the data buffer into the record buffer.
- //
- // End ---------------------------------------------------------------------
-
- // constructor PXFieldTypeLong //
-
- inline PXFieldTypeLong::PXFieldTypeLong(PPXField my_field):
- PXFieldTypeBase(my_field)
- {
- char_size = LONGSIZE;
-
- // Create buffer space
-
- data = new long;
- char_dat = new char[char_size + 1];
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Initialize double type fields.
- //
- // Parameters
- //
- // my_field. Pass the field object to copy the handles.
- //
- // Functional Description
- //
- // Set char_size to LONGSIZE for holding the text results of the
- // long value. Create the buffer space for the long number and
- // the character version of the number.
- //
- // End ---------------------------------------------------------------------
-
- // destructor PXFieldTypeLong //
-
- inline PXFieldTypeLong::~PXFieldTypeLong(void)
- {
- delete data;
- data = NULL;
- delete char_dat;
- char_dat = NULL;
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Delete the data and character buffers.
- //
- // End ---------------------------------------------------------------------
-
- // member build of PXFieldTypeLong //
-
- PTStreamable PXFieldTypeLong::build()
- {
- return new PXFieldTypeLong(streamableInit);
- }
-
- TStreamableClass RegPXFieldTypeLong("PXFieldTypeLong",PXFieldTypeLong::build,
- __DELTA(PXFieldTypeLong));
-
- // Description -------------------------------------------------------------
- //
- // When the streamable constructor is called, TStreamable dispatches
- // the build member to construct the object. To do this, it must
- // know where to find this member functions for the specific class.
- // This is the reason for the stream registration.
- //
- // End ---------------------------------------------------------------------
-
- // member read of PXFieldTypeLong //
-
- inline Pvoid PXFieldTypeLong::read(Ripstream)
- {
- return this;
- }
-
- // member write of PXFieldTypeLong //
-
- inline void PXFieldTypeLong::write(Ropstream)
- {
-
- }
-
- // member Get of PXFieldTypeLong //
-
- inline int PXFieldTypeLong::Get(void)
- {
- if((EngDataPtr->Errors.pxerr = PXGetLong(*recHandle,fld,data))
- != PXSUCCESS)
- PXError(ENG_ERROR);
- sprintf(char_dat,"%g",*data);
- return EngDataPtr->Errors.pxerr;
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Get the long data and convert it to character data.
- //
- // Return Value
- //
- // pxerr. Return PDOX error code.
- //
- // End ---------------------------------------------------------------------
-
- // member Put of PXFieldTypeLong //
-
- inline int PXFieldTypeLong::Put(void)
- {
- if((EngDataPtr->Errors.pxerr = PXPutLong(*recHandle,fld,*data))
- != PXSUCCESS)
- PXError(ENG_ERROR);
- return EngDataPtr->Errors.pxerr;
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Put the data from the data buffer into the record buffer.
- //
- // End ---------------------------------------------------------------------
-
- // constructor PXFieldTypeShort //
-
- inline PXFieldTypeShort::PXFieldTypeShort(PPXField my_field):
- PXFieldTypeBase(my_field)
- {
- // Copy record and field handles
-
- char_size = SHORT_SIZE;
-
- // Create buffer space
-
- data = new short;
- char_dat = new char[char_size + 1];
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Initialize double type fields.
- //
- // Parameters
- //
- // my_field. Pass the field object to copy the handles.
- //
- // Functional Description
- //
- // Set char_size to SHORT_SIZE for holding the text results of the
- // short value. Create the buffer space for the short number and
- // the character version of the number.
- //
- // End ---------------------------------------------------------------------
-
- // destructor PXFieldTypeShort //
-
- inline PXFieldTypeShort::~PXFieldTypeShort(void)
- {
- delete data;
- data = NULL;
- delete char_dat;
- char_dat = NULL;
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Delete the data and character buffers.
- //
- // End ---------------------------------------------------------------------
-
- // member build of PXFieldTypeShort //
-
- PTStreamable PXFieldTypeShort::build()
- {
- return new PXFieldTypeShort(streamableInit);
- }
-
- TStreamableClass RegPXFieldTypeShort("PXFieldTypeShort",PXFieldTypeShort::build,
- __DELTA(PXFieldTypeShort));
-
- // Description -------------------------------------------------------------
- //
- // When the streamable constructor is called, TStreamable dispatches
- // the build member to construct the object. To do this, it must
- // know where to find this member functions for the specific class.
- // This is the reason for the stream registration.
- //
- // End ---------------------------------------------------------------------
-
- // member read of PXFieldTypeShort //
-
- inline Pvoid PXFieldTypeShort::read(Ripstream)
- {
- return this;
- }
-
- // member write of PXFieldTypeShort //
-
- inline void PXFieldTypeShort::write(Ropstream)
- {
-
- }
-
- // member Get of PXFieldTypeShort //
-
- inline int PXFieldTypeShort::Get(void)
- {
- if((EngDataPtr->Errors.pxerr = PXGetShort(*recHandle,fld,data))
- != PXSUCCESS)
- PXError(ENG_ERROR);
- sprintf(char_dat,"%d",*data);
- return EngDataPtr->Errors.pxerr;
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Get the short data and convert it to character data.
- //
- // Return Value
- //
- // pxerr. Return PDOX error code.
- //
- // End ---------------------------------------------------------------------
-
- // member Put of PXFieldTypeShort //
-
- inline int PXFieldTypeShort::Put(void)
- {
- if((PXPutShort(*recHandle,fld,*data)) != PXSUCCESS)
- PXError(ENG_ERROR);
- return EngDataPtr->Errors.pxerr;
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Put the data from the data buffer into the record buffer.
- //
- // End ---------------------------------------------------------------------
-
- // constructor PXFieldTypeDate //
-
- inline PXFieldTypeDate::PXFieldTypeDate(PPXField my_field):
- PXFieldTypeBase(my_field)
- {
- // Copy record and field handles
-
- char_size = DATE_SIZE;
-
- // Create buffer space
-
- data = new DATES;
- char_dat = new char[char_size + 1];
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Initialize DATES type fields.
- //
- // Parameters
- //
- // my_field. Pass the field object to copy the handles.
- //
- // Functional Description
- //
- // Set char_size to DATE_SIZE for holding the text results of the
- // DATES value. Create the buffer space for the DATES structure and
- // the character version of the structure.
- //
- // End ---------------------------------------------------------------------
-
- // destructor PXFieldTypeDate //
-
- inline PXFieldTypeDate::~PXFieldTypeDate(void)
- {
- delete data;
- data = NULL;
- delete char_dat;
- char_dat = NULL;
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Delete the data and character buffers.
- //
- // End ---------------------------------------------------------------------
-
- // member build of PXFieldTypeDate //
-
- PTStreamable PXFieldTypeDate::build()
- {
- return new PXFieldTypeDate(streamableInit);
- }
-
- TStreamableClass RegPXFieldTypeDate("PXFieldTypeDate",PXFieldTypeDate::build,
- __DELTA(PXFieldTypeDate));
-
- // Description -------------------------------------------------------------
- //
- // When the streamable constructor is called, TStreamable dispatches
- // the build member to construct the object. To do this, it must
- // know where to find this member functions for the specific class.
- // This is the reason for the stream registration.
- //
- // End ---------------------------------------------------------------------
-
- // member read of PXFieldTypeDate //
-
- inline Pvoid PXFieldTypeDate::read(Ripstream)
- {
- return this;
- }
-
- // member write of PXFieldTypeDate //
-
- inline void PXFieldTypeDate::write(Ropstream)
- {
-
- }
-
- // member Get of PXFieldTypeDate //
-
- inline int PXFieldTypeDate::Get(void)
- {
- if((EngDataPtr->Errors.pxerr = PXGetDate(*recHandle,fld,
- &data->date)) != PXSUCCESS)
- {
- PXError(ENG_ERROR);
- return EngDataPtr->Errors.pxerr;
- }
- if((EngDataPtr->Errors.pxerr = PXDateDecode(data->date,
- &data->month,&data->day,
- &data->year)) != PXSUCCESS)
- PXError(ENG_ERROR);
- else
- sprintf(char_dat,"%02d-%02d-%02d",data->month,data->day,
- data->year);
- return EngDataPtr->Errors.pxerr;
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Get the DATES data, decodes it and convert it to character data.
- //
- // Return Value
- //
- // pxerr. Return PDOX error code.
- //
- // End ---------------------------------------------------------------------
-
- // member Put of PXFieldTypeDate //
-
- inline int PXFieldTypeDate::Put(void)
- {
- if((EngDataPtr->Errors.pxerr = PXDateEncode(data->month,
- data->day,data->year,
- &data->date)) != PXSUCCESS)
- {
- PXError(ENG_ERROR);
- return EngDataPtr->Errors.pxerr;
- }
- if((EngDataPtr->Errors.pxerr = PXPutDate(*recHandle,fld,data->date))
- != PXSUCCESS)
- PXError(ENG_ERROR);
- return EngDataPtr->Errors.pxerr;
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Put the data from the data buffer into the record buffer.
- //
- // End ---------------------------------------------------------------------
-
- // constructor PXField //
-
- PXField::PXField(PPXRec my_object,FIELDHANDLE fldHandle)
- {
- // Point to the engine object data
-
- EngDataPtr = my_object->EngDataPtr;
-
- // Copy record and field handles
-
- recHandle = my_object->recHandle;
- fld = fldHandle;
-
- // Make the space you need to store the field type and
- // name.
-
- fldtype = new char[MAX_FLD_TYPE_SIZE];
- fldname = new char[MAX_FLD_NAME_SIZE];
-
- // Get the name and type of the field
-
- if((EngDataPtr->Errors.pxerr = PXFldName(EngDataPtr->tblHandle,fld,
- MAX_FLD_NAME_SIZE,fldname)) != PXSUCCESS)
- {
- PXError(ENG_ERROR);
- return;
- }
- if((EngDataPtr->Errors.pxerr = PXFldType(EngDataPtr->tblHandle,fld,
- MAX_FLD_TYPE_SIZE,fldtype)) != PXSUCCESS)
- {
- PXError(ENG_ERROR);
- return;
- }
-
- // Caste to the right field type and make that object
-
- switch(*fldtype)
- {
- case 'A':
- {
- my_type = new PXFieldTypeChar(this,atoi(fldtype + 1));
- break;
- }
- case 'D':my_type = new PXFieldTypeDate(this);break;
- case 'S':my_type = new PXFieldTypeShort(this);break;
- case '$':my_type = new PXFieldTypeDouble(this);break;
- case 'N':my_type = new PXFieldTypeDouble(this);break;
- }
- }
-
- // Summary -----------------------------------------------------------------
- //
- // This constructor sets up each field of the database
- //
- // Parameters
- //
- // tblHandle. This is the handle for the open table.
- //
- // recHandle. This is the record handle for the current record.
- //
- // Functional Description
- //
- // 1. Copy all the parameters.
- //
- // 2. Make some space to save the field name and type.
- //
- // 3. Get the name and type of the field.
- //
- // 4. Call the constructor for the given type.
- //
- // End ---------------------------------------------------------------------
-
- // constructor PXField //
-
- PXField::PXField(PPXField my_field)
- {
- EngDataPtr = my_field->EngDataPtr;
- fld = my_field->fld;
- recHandle = my_field->recHandle;
- fldtype = NULL;
- fldname = NULL;
- my_type = NULL;
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Copies info to initialize engine object. It's very important that
- // you NULL your pointers out so that the destructor does not delete
- // something that was never allocated!!
- //
- // End ---------------------------------------------------------------------
-
- PXField::~PXField(void)
- {
- delete fldtype;
- fldtype = NULL;
- delete fldname;
- fldname = NULL;
- delete my_type;
- my_type = NULL;
- }
-
- // member build of PXField //
-
- PTStreamable PXField::build()
- {
- return new PXField(streamableInit);
- }
-
- TStreamableClass RegPXField("PXField",PXField::build,
- __DELTA(PXField));
-
- // Description -------------------------------------------------------------
- //
- // When the streamable constructor is called, TStreamable dispatches
- // the build member to construct the object. To do this, it must
- // know where to find this member functions for the specific class.
- // This is the reason for the stream registration.
- //
- // End ---------------------------------------------------------------------
-
- // member read of PXField //
-
- inline Pvoid PXField::read(Ripstream)
- {
- return this;
- }
-
- // member write of PXField //
-
- inline void PXField::write(Ropstream)
- {
-
- }
-
- // member Get of PXField //
-
- inline char *PXField::Get() /* Get the field data */
- {
- if(my_type->Get())
- return NULL;
- return my_type->RetCharData();
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Gets data of the field type. and returns it.
- //
- // Return Value
- //
- // returns character version of field data for any type.
- //
- // End ---------------------------------------------------------------------
-
- // member RetCharSize of PXField //
-
- inline int PXField::RetCharSize()
- {
- return my_type->RetCharSize();
- }
-
- // Summary -----------------------------------------------------------------
- //
- // Returns the number of characters it takes to display this field.
- //
- // Return Value
- //
- // Returns the number of characters for this field type.
- //
- // End ---------------------------------------------------------------------
-
- // member PXError of PXField //
-
- inline void PXField::PXError(int org)
- {
- // Calls base class error handler.
-
- PXEngObject::PXError(org);
-
- // Call the parents error handler
-
- EngDataPtr->PXEObjPtr->EngDataPtr->Errors.pxerr =
- EngDataPtr->Errors.pxerr;
- EngDataPtr->PXEObjPtr->PXError(EngDataPtr->Errors.Origin);
- }
-
- // Summary -----------------------------------------------------------------
- //
- // If you have an error, the parent error handler is called.
- //
- // End ---------------------------------------------------------------------
-
- #endif // PXFIELD_CPP //
-